<template>
  <div>
    <div class="header">
      <div class="title">
        资料上传
      </div>
      <el-button @click="onPageBack">返回</el-button>
    </div>
    <SubmitForm
      style="padding-right: 30%"
      :disabled="true"
      :rule-form="ruleForm"
      :rules="rules"
      :form-list="formList"
      :show-close="false"
      @close="onPageBack"
      @save="onSave"
    />
  </div>
</template>

<script>
import { http } from '@/api'
export default {
  name: 'DataUploadForm',
  data() {
    return {
      dialogValue: false,
      ruleForm: {
      },
      rules: {
      },
      formList: [
        {
          key: 'projectName',
          name: 'input',
          label: '项目名称',
          colSpan: 24
        },
        {
          key: 'pocket',
          name: 'input',
          type: 'number',
          label: '资金（万元）',
          colSpan: 12
        },
        {
          key: 'capital',
          name: 'input',
          label: '投资方',
          colSpan: 12
        },
        {
          key: 'projectContent',
          name: 'input',
          type: 'textarea',
          label: '项目内容',
          colSpan: 24,
          rows: 5
        },
        {
          name: 'title',
          label: '附件资料',
          colSpan: 24
        },
        {
          key: 'files',
          name: 'files',
          multiple: true,
          defaultValue: [],
          label: '',
          description: ''
        }
      ],
      currentDetail: {}
    }
  },
  created() {

  },
  methods: {
    getForm() {
      const form = {
        id: undefined,
        category: 1,
        files: []
      }
      this.formList.forEach(el => {
        if (el.key) {
          form[el.key] = el.defaultValue || ''
        }
      })
      form.files = []
      return form
    },
    async open(item) {
      this.currentDetail = item
      this.ruleForm = this.getForm()
        http.project_center.read({
            id: item.id
        }).then(res => {
            if (item) {
                for (const key in this.ruleForm) {
                    this.ruleForm[key] = res.data[key] ? res.data[key] : this.ruleForm[key]
                }
                this.ruleForm.files = []
            }
        })
      this.dialogValue = true
    },
    onPageBack() {
     this.ruleForm.files = []
      this.$emit('back')
    },
    onSave() {
      http.meeting_data.create({
        projectId: this.currentDetail.id,
        files: this.ruleForm.files
      }).then(res => {
        this.$message.success(res.msg)
        this.onPageBack()
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
